﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Revit;
using YArchitech.Revit.MEP.Opening;

namespace HYRMEOpening
{
	public static class RequestHandler
	{
		public static void ClearTag(UIApplication uiapp)
		{
			try
			{
				DbOpeningBase.ClearTag(uiapp.ActiveUIDocument.Document);
			}
			catch (Exception)
			{
			}
		}

		public static void DelOpening(Autodesk.Revit.DB.Document doc, List<FamilyInstance> fiList)
		{
			Transaction transaction = new Transaction(doc, "DelOpening");
			try
			{
				transaction.Start();
				foreach (FamilyInstance elem in fiList)
				{
					doc.DeleteElement(elem);
				}
				transaction.Commit();
			}
			catch
			{
				transaction.RollBack();
			}
		}

		public static void AddTag(UIApplication uiApp, BindingList<DbOpeningBase> opiningList)
		{
			foreach (DbOpeningBase dbOpeningBase in opiningList)
			{
				dbOpeningBase.AddOpeningTag(uiApp, TagStyle.PositionAndSize);
			}
		}

		public static void ChangeTag(UIApplication uiapp, DbOpeningBase opining)
		{
			opining.UpdateTag(uiapp, TagStyle.PositionAndSize);
		}

		public static void Regenerate(UIDocument uiDoc)
		{
			Transaction transaction = new Transaction(uiDoc.Document, "reg");
			transaction.Start();
			try
			{
				uiDoc.Document.Regenerate();
				transaction.Commit();
			}
			catch
			{
				transaction.RollBack();
			}
		}
	}
}
